<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="秒杀ID" width="95">
        <template slot-scope="scope">
          {{ scope.row.seckillId }}
        </template>
      </el-table-column>
      <el-table-column label="商品">
        <template slot-scope="scope">
          {{scope.row.goods.goodsName}}
        </template>
      </el-table-column>
      <el-table-column label="商品图片" width="140px">
        <template slot-scope="scope">
          <img :src="scope.row.goodsImg" width="120px">
        </template>
      </el-table-column>
        <el-table-column label="商品数量"  align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.number }}</span>
          </template>
        </el-table-column>
      <el-table-column label="秒杀开始时间"  align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.startTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="秒杀结束时间"  align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="原价"  align="center">
        <template slot-scope="scope">
          {{ scope.row.goods.goodsPrice }}
        </template>
      </el-table-column>

      <el-table-column label="操作"  align="center">
        <template slot-scope="scope">
          <!--          <el-button type="success" round @click="dialogFormVisiblePost = true">添加</el-button>-->
<!--          <el-button type="primary" round @click="dialogFormVisiblePutId(scope.$index)">修改</el-button>-->
          <el-button type="danger" icon="el-icon-delete" circle @click="del(scope.row.seckillId)"> </el-button>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination
      @current-change="handleCurrentChange"
      :page-size="5"
      :current-page.sync="currentPage"
      background
      layout="prev, pager, next, jumper"
      :total="count">
    </el-pagination>
  </div>
</template>

<script>
  // import { getList } from '@/api/table'
  import { listApi,pagingList,delIdApi } from '@/api/server-seckill'



export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      currentPage:null, //页数
      count: 18, //赋值意义，代码出差，分页不会有问题(好像也没啥用)
      list: null,
      listLoading: true
    }
  },
  created() {
    this.fetchData()
  },
  methods: {

    // 根据id删除
    del(id) {
      var that = this;
      delIdApi(id, function(msg) {
        alert(msg.data.msg);
        if(msg.data.msg == '删除成功'){
          that.fetchData()
        }

      })
    },

    //分页
    handleCurrentChange(val) {
      var that = this;
      pagingList(val,function(msg) {
        that.list = msg.data;
        if (msg.msg === '查询成功！') {
          that.listLoading = false
        }
      })
    },

    fetchData() {
      var that = this
      that.listLoading = true
      listApi(function(msg) {
        console.log(msg);
        that.list = msg.data;
        that.count = msg.count;  //分页条数
        if (msg.msg === '查询成功！') {
          that.listLoading = false
        }
      })

    }
  }
}
</script>
